﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Utility;
using Utility.Service;

namespace Site
{
    public partial class Tech_Detail : UserControl
    {
        private int intDefaultTech=0;

        public int DefaultTech
        {
            set { this.intDefaultTech = value; }
        }

        public Tech_Detail()
        {
            InitializeComponent();
            this.myMenu.Logo = "1";
            this.Loaded += new RoutedEventHandler(Technology_Loaded);
        }

        void Technology_Loaded(object sender, RoutedEventArgs e)
        {
            //菜单下滑动画
            DoubleAnimation animation = new DoubleAnimation();
            animation.From = -83;
            animation.To = 0;
            animation.Duration = new Duration(new TimeSpan(0, 0, 1));
            Storyboard.SetTarget(animation, myMenu);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Canvas.TopProperty));
            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            storyboard.Begin();
            InitContent();
        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.intDefaultTech = 0;
            InitContent();
        }

        private void Image_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            this.intDefaultTech = 1;
            InitContent();
        }

        private void Image_MouseLeftButtonDown_2(object sender, MouseButtonEventArgs e)
        {
            this.intDefaultTech = 2;
            InitContent();
        }

        private void Image_MouseLeftButtonDown_3(object sender, MouseButtonEventArgs e)
        {
            this.intDefaultTech = 3;
            InitContent();
        }

        private void InitContent()
        {
            ServiceClient client = CUtility.GetServiceClient();
            client.ReadItemsCompleted += new EventHandler<ReadItemsCompletedEventArgs>(client_ReadItemsCompleted);
            client.ReadItemsAsync(2);
        }

        void client_ReadItemsCompleted(object sender, ReadItemsCompletedEventArgs e)
        {
            if (null == e.Error)
            {
                this.htmlHost.SourceHtml = "";
                if (null != e.Result)
                {
                    this.htmlHost.SourceHtml = e.Result[this.intDefaultTech].Content;
                    this.tbNavTitle.Text = e.Result[this.intDefaultTech].Title;
                }
                this.LayoutRoot.UpdateLayout();
            }
            else
            {
                throw e.Error;
            }
        }

        private void lnkHome_Click(object sender, RoutedEventArgs e)
        {
            App app = (App)Application.Current;
            app.RedirectTo(new Home());
        }

        private void lnkTech_Click(object sender, RoutedEventArgs e)
        {
            App app = (App)Application.Current;
            app.RedirectTo(new Technology());
        }

        
    }
}
